var http = require('http');
var querystring = require('querystring');
var model = function() {}
model.post = function(host,port,path,info,cb,errorcb) {
    var contents = querystring.stringify(info)
    var options = {
        host:host,
        port : port,
        path:path,
        method:'POST',
        headers:{
            'Content-Type':'application/x-www-form-urlencoded',
            'Content-Length':contents.length
        }
    }
    var req = http.request(options, function(res){
        var _data='';
        res.on('data', function(chunk){
            _data += chunk;
        });
        res.on('end', function(){
            cb(_data)
        });

    });
    req.on('error', (error) => {
      if(errorcb)
        errorcb(error)
    })
    req.write(contents);
    req.end()
}


module.exports = model


 

 
